<?php

function invokeApi ($method, $apikey, $secret, $params) {

  $params = $params . "&seq=" . microtime(true) * 10000;
  // $sig = sha1($params.sha1($secret));
  $sig = sha1($params.$secret);
  $url = "http://devzone.ringful.com/" . $method . "/apikey/" . $apikey . "?" . $params . "&sig=" . $sig;

  error_log ("URL is " . $url);

  $result = array ();

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, 'M.A.X PHP5 Client API v1.2 (curl) ' . phpversion());
  $resp = curl_exec($ch);

  error_log ("Response is " . $resp);

  $bytes = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
  $result['content'] = substr($resp, -($bytes));
  $result['httpcode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  return $result;
}

?>
